﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Interface_Tier;
using Transfer_Object_Tier;

namespace eSolution_HRMSS.Winforms.QuaTrinhLamViec
{
    public partial class FR_ThayDoiLuong : DevExpress.XtraEditors.XtraForm
    {
        IHRM_PROCESS_SALARYData _IHRM_PROCESS_SALARYData;
        ICommonCode _icommon;
        eSolution_HRMSS.HRMSS_Ultil util = new HRMSS_Ultil();
        Guid currentId;
        Guid new_id;
        bool isUpdate = false;
         public FR_ThayDoiLuong(bool _isUpdate)
        {
            InitializeComponent();
            isUpdate = _isUpdate;
        }

         public FR_ThayDoiLuong(bool _isUpdate, Guid _currentId)
        {
            InitializeComponent();
            isUpdate = _isUpdate;
            currentId = _currentId;
        }


        private void FR_ThayDoiLuong_Load(object sender, EventArgs e)
        {
            _IHRM_PROCESS_SALARYData = (IHRM_PROCESS_SALARYData)Activator.GetObject(typeof(IHRM_PROCESS_SALARYData), util.ChuoiPROCESS_SALARYData);
            _icommon = (ICommonCode)Activator.GetObject(typeof(ICommonCode), util.Chuoicommon);
        }
        private HRM_PROCESS_SALARY lay_thong_tin()
        {
            string ngachluonghientai = lu_ngachluonghientai.EditValue.ToString();
            string bacluonghientai = lu_bacluonghientai.EditValue.ToString();
            string hesohientai = lu_hesoluonghientai.EditValue.ToString();
            string luongtoithieuhientai = lu_luongtoithieuhienhai.EditValue.ToString();
            string luongcanbanhientai = lu_luongcanbanhientai.EditValue.ToString();
            string ngachluongmoi = lu_ngachluongmoi.EditValue.ToString();
            string bacluongmoi = lu_bacluongmoi.EditValue.ToString();
            string hesomoi = lu_hesoluongmoi.EditValue.ToString();
            string luongtoithieumoi = lu_luongtoithieumoi.EditValue.ToString();
            string luongcanbanmoi = lu_luongcanbanmoi.EditValue.ToString();
            string lydothaydoi = txtlydothaydoi.Text;
            string soquyetdinh = txtsoquyetdinh.Text;
            string nguoibanhanh = txtnguoibanhanh.Text;

            DateTime ngaythaydoi = dtngaythaydoi.DateTime;

            HRM_PROCESS_SALARY changerSalary = new HRM_PROCESS_SALARY();
            changerSalary.OldRankSalary = ngachluonghientai;
            changerSalary.OldStepSalary =int.Parse( bacluonghientai);
            changerSalary.OldCoefficientSalary =double.Parse( hesohientai);
            changerSalary.OldMinimumSalary = decimal.Parse(luongtoithieuhientai);
            changerSalary.OldBasicSalary =decimal.Parse( luongcanbanhientai);
            changerSalary.NewRankSalary = ngachluongmoi;
            changerSalary.NewStepSalary = int.Parse(bacluongmoi);
            changerSalary.NewCoefficientSalary =double.Parse( bacluongmoi);
            changerSalary.NewMinimumSalary = decimal.Parse(luongtoithieumoi);
            changerSalary.NewBasicSalary =decimal.Parse(luongcanbanmoi);
            changerSalary.Reason = lydothaydoi;
            changerSalary.DecideNumber = soquyetdinh;
            changerSalary.Person = nguoibanhanh;
            changerSalary.Date = ngaythaydoi;
            return changerSalary;
        }
        private void load_info()
        {
            DataTable dt = _IHRM_PROCESS_SALARYData.HRM_PROCESS_SALARY_Get(currentId).Tables[0];
            foreach (DataRow dr in dt.Rows)
            {
                lu_ngachluonghientai.EditValue = dr["OldRankSalary"].ToString();
                lu_bacluonghientai.EditValue = dr["OldStepSalary"].ToString();
                lu_hesoluonghientai.EditValue = dr["OldCoefficientSalary"].ToString();
                lu_luongtoithieuhienhai.EditValue = dr["OldMinimumSalary"].ToString();
                lu_luongcanbanhientai.EditValue = dr["OldBasicSalary"].ToString();
                lu_ngachluongmoi.EditValue = dr["NewRankSalary"].ToString();
                lu_bacluongmoi.EditValue = dr["NewStepSalary"].ToString();
                lu_hesoluongmoi.EditValue = dr["NewCoefficientSalary"].ToString();
                lu_luongtoithieumoi.EditValue = dr["NewMinimumSalary"].ToString();
                lu_luongcanbanmoi.EditValue = dr["NewBasicSalary"].ToString();
                txtlydothaydoi.Text = dr["Reason"].ToString();
                txtsoquyetdinh.Text = dr["DecideNumber"].ToString();
                txtnguoibanhanh.Text = dr["Person"].ToString();
                dtngaythaydoi.DateTime = DateTime.Parse(dr["Date"].ToString());
            }
        }
    }
}